// 时间戳转化为多少时间前显示
export const timestampToRelativeTime = (timestamp) => {
	const now = Date.now();
	const diff = now - timestamp; // 时间差（毫秒）

	const seconds = Math.floor(diff / 1000);
	const minutes = Math.floor(seconds / 60);
	const hours = Math.floor(minutes / 60);
	const days = Math.floor(hours / 24);

	if (days < 1) {
		if (hours < 1) {
			if (minutes < 1) {
				return '刚刚';
			}
			return `${minutes}分钟前`;
		}
		return `${hours}小时前`;
	}

	// 超过1天但不足30天，显示"X天前"
	if (days < 30) {
		return `${days}天前`;
	}

	const months = Math.floor(days / 30);
	// 超过1个月但不足12个月，显示"X个月前"
	if (months < 12) {
		return `${months}月前`;
	}

	const years = Math.floor(months / 12);
	// 超过1年，显示"X年前"
	return `${years}年前`;
}